import { createSlice } from "@reduxjs/toolkit";
import attrApi from "@/api/attr/attr";

interface getAttrParams{
    category1Id:number,
    category2Id:number,
    category3Id:number
}

const attrSlice = createSlice({
    name:'attr',
    initialState:{
      attrList: []
    },
      reducers:{
           pageAttrList:(state,{payload})=>{
              state.attrList = payload
           }
      }
})


// 暴露actions函数

export const {pageAttrList} = attrSlice.actions 

//书写异步请求代码
// 获取属性列表
export const asyncGetAttrList = (payload:getAttrParams)=>{
   return async(dispatch:any)=>{
     try {
       let result = await  attrApi.attrInfoList(payload.category1Id,payload.category2Id,payload.category3Id)
      //  console.log(result,'获取属性值的数据')
       dispatch(pageAttrList(result))
     } catch (error) {
        return Promise.reject(error)
     }
   }
}     



export default attrSlice.reducer

